<?php

namespace App\Listeners;

use App\Events\Message;
use Illuminate\Support\Facades\DB;

class MessageListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  \App\Events\Message  $event
     * @return void
     */
    public function handle(Message $event)
    {
        DB::table('user_messages')
            ->insert([
                'user_id' => $event->message['user_id'],
                'type' => $event->message['type'],
                'content' => $event->message['content'],
                'is_read' => 1,
                'created_at' => date('Y-m-d H:i:s')
            ]);
    }
}
